package com.huiqiao.lesson9.controller;


import com.huiqiao.lesson9.annotation.Log;
import com.huiqiao.lesson9.entity.SysUser;
import com.huiqiao.lesson9.service.SysUserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/user")
@Log4j2
public class SysUserController extends BaseController {

    @Resource
    SysUserService userService;

    @Log("用户执行了注册操作1")
    @PostMapping("/register")
    public AppResponse register() {
        SysUser user = new SysUser();
        user.setUserName("陈峰1");
        user.setPhonenumber("37681101376");
        user.setNickName("小陈同学");
        user.setEmail("664839088@qq.com");
        user.setSex("0");//0男 1女 2未知
        user.setAvatar("https://www.baidu.com");
        user.setPassword("Aa123456");
        return success(userService.register(user));
//        try {
//            return success(userService.register(user));
//        } catch (Exception e) {
//            log.error(e.getMessage());
//        }
//        return fail();
    }

    @Log("用户执行了注册操作2")
    @GetMapping("test")
    public AppResponse test() {
        return success(userService.register2(null));
    }
}
